/**
 * Copyright (c) 2018, Alex. All rights reserved.
 */
package com.oschina.bottle.utils;

import com.oschina.bottle.common.enums.MsgEnum;
import com.oschina.bottle.common.exception.ErrorCodeException;
import org.springframework.util.Assert;

/**
 * 异常
 *
 * @author <a href="mailto:zhongchao@gegejia.com">zhong</a>
 * @version 1.0 2018/2/5
 * @since 1.0
 */
public class ExceptionUtils {

    /**
     * msgEnum转换为ErrorCodeException
     *
     * @param msgEnum   枚举类
     * @param <T>       泛型
     * @return          ErrorCodeException
     */
    public static <T extends ErrorCodeException> T  genWithEnum(MsgEnum<Long> msgEnum) {
        Assert.notNull(msgEnum, "this MsgEnum must not be null");
        return (T) new ErrorCodeException(msgEnum.getCode(), msgEnum.getMsg());
    }
}